{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可以\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from abc import abstractmethod , ABCMeta\n",
    "class GPD(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def test(self):\n",
    "        pass\n",
    "class fujun(GPD):\n",
    "    def test(self):\n",
    "        print('可以')\n",
    "class main:\n",
    "    def __init__(self,gpd):\n",
    "        self.gpd=gpd\n",
    "    def show(self):\n",
    "        self.gpd.test()\n",
    "def make(factory):\n",
    "    gpd=factory.test()\n",
    "    return main(gpd)\n",
    "ma=main(fujun())\n",
    "p=ma.show()\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "瓜子脸,好眼睛,长腿,胖子\n",
      "漂亮的脸蛋,眼睛,腿长,细腰\n"
     ]
    }
   ],
   "source": [
    "import random \n",
    "from abc import abstractmethod,ABCMeta\n",
    "\n",
    "class player():\n",
    "    def __init__(self,face=None,body=None,arm=None,leg=None):\n",
    "        self.face=face\n",
    "        self.arm=arm\n",
    "        self.leg=leg\n",
    "        self.body=body\n",
    "    def __str__(self):\n",
    "        return \"%s,%s,%s,%s\"%(self.face,self.arm,self.leg,self.body)\n",
    "class playerbuilder(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def build_face(self):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def build_arm(self):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def build_leg(self):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def build_body(self):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def get_player(self):\n",
    "        pass\n",
    "class beautifulbuild(playerbuilder):\n",
    "    def __init__(self):\n",
    "        self.player=player()\n",
    "    def build_face(self):\n",
    "        self.player.face='漂亮的脸蛋'\n",
    "    def build_arm(self):\n",
    "        self.player.arm='眼睛'\n",
    "    def build_body(self):\n",
    "        self.player.body='细腰'\n",
    "    def build_leg(self):\n",
    "        self.player.leg='腿长'\n",
    "    def get_player(self):\n",
    "        return self.player\n",
    "class randombuilder(playerbuilder):\n",
    "    def __init__(self):\n",
    "        self.player=player()\n",
    "    def build_face(self):\n",
    "        self.player.face=random.choice(['瓜子脸','圆脸'])\n",
    "    def build_arm(self):\n",
    "        self.player.arm=random.choice(['好眼睛','坏眼睛'])\n",
    "    def build_body(self):\n",
    "        self.player.body=random.choice(['苗条','胖子'])\n",
    "    def build_leg(self):\n",
    "        self.player.leg=random.choice(['长腿','短腿'])\n",
    "    def get_player(self):\n",
    "        return self.player\n",
    "class playerdirector:\n",
    "    def __init__(self,builder):\n",
    "        self.builder=builder\n",
    "    def builder_player(self):\n",
    "        self.builder.build_body()\n",
    "        self.builder.build_face()\n",
    "        self.builder.build_arm()\n",
    "        self.builder.build_leg()\n",
    "        return self.builder.get_player()\n",
    "pd=playerdirector(randombuilder())\n",
    "p=pd.builder_player()\n",
    "print(p)\n",
    "pg=playerdirector(beautifulbuild())\n",
    "res=pg.builder_player()\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
